package br.com.sgs.fachada;

import br.com.sgs.dao.*;
import br.com.sgs.entity.*;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;


public class Fachada implements IFachada{
	
	private Map<String, IDAO> dao = new HashMap<String, IDAO>();
	
	public Fachada(){
    
		dao.put(Instituicao.class.getName(), new DAOInstituicao());
		dao.put(Campus.class.getName(), new DAOCampus());
                dao.put(Departamento.class.getName(), new DAODepartamento());
                dao.put(ModeloSolicitacao.class.getName(), new DAOModeloSolicitacao());
                dao.put(Solicitacao.class.getName(), new DAOSolicitacao());
                dao.put(Aluno.class.getName(), new DAOAluno());
                dao.put(Funcionario.class.getName(), new DAOFuncionario());
                dao.put(Status.class.getName(), new DAOStatus());
                dao.put(Processo.class.getName(), new DAOProcesso());
                dao.put(Etapa.class.getName(), new DAOEtapa());
                
	}
	
    @Override
    public void inserir(Object o) throws ClassNotFoundException, SQLException, Exception {

        IDAO d = dao.get(o.getClass().getName()); //Recupera o objeto do map conforme o objeto passado por par�metro

        try {
            d.incluir(o);//insere o objeto
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

	@Override
	public void alterar(Object o) throws ClassNotFoundException, SQLException,Exception {
		
               IDAO d = dao.get(o.getClass().getName()); //Recupera o objeto do map conforme o objeto passado por par�metro

		try {
		d.alterar(o);//altera o objeto
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void excluir(Object o) throws ClassNotFoundException, SQLException,Exception {
		IDAO d = dao.get(o.getClass().getName()); //Recupera o objeto do map conforme o objeto passado por par�metro

		try {
		d.excluir(o);//exclui o objeto
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
